﻿#region Using's

using System.Collections;
using System.Collections.Generic;
using System.Linq;

using MyUtils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Test.MyUtils.TestHelp;

#endregion

namespace Test.MyUtils
{
	[TestClass]
	public class CollectionExtensions : FixtureMsTest
	{
		class a : d
		{
			public new string M()
			{
				return "A";
			}
		}

		class b {}

		class c {}

		class d
		{
			public string M()
			{
				return "D";
			}
		}

		class myCol : IEnumerable<a>, IEnumerable<b>
		{
			readonly IEnumerable<a> a = new List<a>
			{
				new a(),
			};

			readonly IEnumerable<b> b = new List<b>
			{
				new b(),
				new b(),
			};

			readonly IEnumerable<c> c = new List<c>
			{
				new c(),
				new c(),
				new c(),
			};

			#region IEnumerable<a> Members

			public IEnumerator<a> GetEnumerator()
			{
				return a.GetEnumerator();
			}

			IEnumerator IEnumerable.GetEnumerator()
			{
				return c.GetEnumerator();
			}

			#endregion

			#region IEnumerable<b> Members

			IEnumerator<b> IEnumerable<b>.GetEnumerator()
			{
				return b.GetEnumerator();
			}

			#endregion
		}

		readonly myCol test = new myCol();

		[TestMethod]
		public void Should_allow_to_cast_collection_that_implements_several_ienumerabels()
		{
			Assert.AreEqual(1, test.Cast<a, d>().Cast<d>().Count());
			Assert.AreEqual("D", test.Cast<a, d>().Cast<d>().First().M());
			Assert.AreEqual(2, test.Cast<b, b>().Cast<b>().Count());
		}
	}
}